import { compose, applyMiddleware, createStore } from 'redux';
import thunk from 'redux-thunk';
import logger from 'redux-logger';
import reducer from './reducer';

const composeEnhancers = (typeof window !== 'undefined' && window.__REDUX_DEVTOOLS_EXTENSION_COMPOSE__) || compose;

export default function configureStore(initialState) {
  const middlewares = [thunk];

  if (process.env.NODE_ENV === 'development')
    middlewares.push(logger);

  return createStore(reducer, initialState, composeEnhancers(applyMiddleware(...middlewares)));
}